package cate.game.role.res.guild.msg;

import cate.common.rpc.path.RpcCommonPath;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdGuild;
import cate.game.role.res.guild.po.GuildPO;
import easy.java.dev.note.NoteField;
import easy.java.struct.ref.StringRef;

import java.util.Objects;

@ClientMsg(title = "某个公会详情数据 の 请求")
public class GuildViewDetailReq implements MsgInput {
    @NoteField(value = "公会唯一id")
    public String guildId;

    @NoteField(value = "游戏服ID", detail = "-1: 查看本服公会详情 其他:判断是否跨服查看(可能被合服到本地)")
    public int srvId = -1;

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.GUILD_VIEW_DETAIL_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        if (game.config.isLocal(srvId)) {
            GuildPO guild = game.res.guild.getGuild(guildId);
            if (Objects.nonNull(guild)) {
                cc.getRole().sendNow(new GuildViewDetailResp(guild));
            } else {
                game.notice.message(cc.getRole(), "查看的公会已经被解散或不存在!");
            }
        } else if (game.config.isRemote(srvId)) {
            GuildViewDetailResp resp = game.rpcSend().requestResponseGame(
                    RpcCommonPath.GUILD_VIEW_DETAIL_G2G, srvId, new StringRef(guildId), GuildViewDetailResp.class);
            cc.getRole().sendNow(resp);
        }
    }
}
